/**
 * @ author: 汪孟苹
 */
define([],function(){
	var tpl = {};
	
	tpl.tab = function(){
		return tab();
	}
	tpl.table = function(){
		var arr = allQuest();
		var h = "";
		h += table();
		h += text();
		for (var i = 0; i < arr.length; i++) {
			h += eval( arr[i] + "()" );
		}
		return h;
	}

	/**
	 * 部分题型
	 */
	var allQuest = function(){
 		return ["group","space","table_relation","static_text","textarea"];
	}
	/**
	 * 根据type判断加载题型
	 */
	var judgeLoadTpl = function(){
		var arr = allQuest();
		for (var i=0; i < arr.length; i++) {
			if( i == 0){
				var h = '{{if quest.type=="'+ arr[i] +'"}}';
			}else{
				h += '{{else if quest.type=="'+ arr[i] +'"}}';
			}
			h += '{{include "selfRecord_'+ arr[i] +'",quest}}';
		}
		h += '{{else}}{{include "selfRecord_text",quest}}{{/if}}';
		return h;
	}

	var tab = function(){
		return 	'<script id="selfRecordComm_tab" type="text/html">'+
				'	<ul class="tab-box clearfix">'+
				'		{{each list as value i}}'+
				'			<li class="ellipsis-1">{{value.taskName}}</li>'+
				'		{{/each}}'+
				'	</ul>'+
				'</script>';
	}

	var table = function(){
		var h = judgeLoadTpl();
		return 	'<script id="selfRecordComm_table" type="text/html">'+
				'	{{if !flag}}'+
				'	<div class="tr">'+
	            '        <div class="td">'+
	            '            <div>题目</div>'+
	            '        </div>'+
	            '        <div class="td">'+
	            '            <div>内容</div>'+
	            '        </div>'+
	            '    </div>'+
	            '	{{/if}}'+
	            '	{{each data.quesList as templ i}}'+
	            '		{{each templ.templData as quest j}}'+ h +'{{/each}}'+
	            '	{{/each}}'+
				'</script>';
	}
	var group = function(){
		var h = judgeLoadTpl();
		return 	'<script id="selfRecord_group" type="text/html">'+
				'	{{each children as quest i}}'+ h +'{{/each}}'+
				'</script>';
	}
	var table_relation = function(){
		return 	'<script id="selfRecord_table_relation" type="text/html">'+
				'	<table class="table table-bordered" data-id="{{id}}">'+
	            '        <tbody>'+
	            '			<tr>'+
	            '				{{each newthead as value i}}'+
	            '					<th>{{value}}</th>'+
	            '				{{/each}}'+
	            '			</tr>'+
	            '			{{each newtbody as value i}}'+
	            '				<tr>'+
	            '					{{each value as item j}}'+
	            '						<td>{{item.text}}</td>'+
	            '					{{/each}}'+
	            '				</tr>'+
	            '			{{/each}}'+
	            '        </tbody>'+
	            '    </table>'+
				'</script>';
	}
	var space = function(){ // 过滤掉
		return 	'<script id="selfRecord_space" type="text/html">'+
				'</script>';
	}
	var static_text = function(){
		return 	'<script id="selfRecord_static_text" type="text/html">'+
				'	<div class="tr">'+
	            ' 		<div class="td width_100">'+
	            ' 			<div>{{label}}</div>'+
	            ' 		</div>'+
	            '   </div>'+
				'</script>';
	}
	var text = function(){
		return 	'<script id="selfRecord_text" type="text/html">'+
				'	<div class="tr">'+
	            ' 		<div class="td">'+
	            ' 			<div>{{label}}</div>'+
	            ' 		</div>'+
	            ' 		<div class="td" {{if bgColor}}style="background:{{bgColor}}"{{/if}}>'+
	            ' 			<div>{{quesValue}}</div>'+
	            ' 		</div>'+
	            '   </div>'+
				'</script>';
	}
	var textarea = function(){
		return 	'<script id="selfRecord_textarea" type="text/html">'+
				'	<div class="tr">'+
	            ' 		<div class="td">'+
	            ' 			<div>{{label}}</div>'+
	            ' 		</div>'+
	            ' 		<div class="td">'+
	            ' 			<div class="textarea"><pre>{{quesValue}}</pre></div>'+
	            ' 		</div>'+
	            '   </div>'+
				'</script>';
	}

	return tpl;
});